import pygtk
pygtk.require("2.0")
import gtk

from jukee.utils.utils import debug, warn, error

class JukeeClientWindow():

  def __init__(self, event_listener):

    self.event_listener = event_listener

    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.set_border_width(10)
    self.refresh_button = gtk.Button("Send file")
    self.refresh_button.connect("clicked", self.send, None)
    self.refresh_button.connect_object("clicked", gtk.Widget.destroy, self.window)
    self.window.connect("destroy", self.destroy)
    self.window.add(self.refresh_button)
    self.refresh_button.show()
    self.window.show()


  def destroy(self, widget, data = None):
    debug("Exiting gtk")
    gtk.main_quit

  def send(self, widget, data = None):
    print "Sending file..."
    chooser = gtk.FileChooserDialog(
      title = None,
      action = gtk.FILE_CHOOSER_ACTION_SAVE,
      buttons = (
        gtk.STOCK_CANCEL,
        gtk.RESPONSE_CANCEL,
        gtk.STOCK_OPEN,
        gtk.RESPONSE_OK
      )
    )
    chooser.set_select_multiple(False)
    response = chooser.run()
    if response == gtk.RESPONSE_OK:
      print chooser.get_filename(), 'selected'
    else:
      print 'Closed, no files selected'
    chooser.destroy()
